from django.contrib import admin

# Register your models here.

from django.contrib import admin
from django.contrib.auth.forms import UserCreationForm
from django.utils.translation import gettext_lazy as _

from book.models import BookType
from book.models import Book


@admin.register(BookType)
class BookTypeAdmin(admin.ModelAdmin):
    """
    类别
    """
    list_display = ['type_name', 'parent', 'create_time', 'update_time']
    fieldsets = (
        (None, {'fields': ('type_name', 'parent', 'order')}),
    )


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    fieldsets = (
        ('基本信息', {'fields': (('title', 'book_type'), ('author', 'isbn'), 'published_date', 'quantity')}),
        ('内容', {'fields': ('intro', 'content')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'password1', 'password2'),
        }),
    )
    add_form = UserCreationForm
    ordering = ['order']

    list_display = ['title', 'book_type', 'author', 'isbn', 'published_date', 'quantity', 'create_time', 'update_time']
    list_filter = ['book_type']
    search_fields = ['title', 'isbn', 'author']
